﻿/**
 * @Description 首页左侧导航
 *@Author  guoyanfei
 */
$(function () {
    setIframeHeight();
    //tree数据绑定
    var setting = {
        data: {
            key: {
                title: "hint"
            },
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: onClick
        }
    };
    var zNodes = GetLeftTreeData();
    $.fn.zTree.init($("#tree"), setting, zNodes);

    //Tree点击事件
    function onClick(event, treeId, treeNode, clickFlag) {
        if (treeNode.isMark != null && treeNode.isMark != "" && treeNode.isMark != undefined) {
            var urlType = treeNode.hint.lastIndexOf("/") + 1;
            var urlTxt = treeNode.hint.substr(urlType).toLocaleLowerCase();
            if (urlTxt == "querysingletb") { //单表服务
                $("#sysIframe").attr("src", "SingleTableContent.html?serviceId=" + treeNode.isMark);
            } else if (urlTxt == "executequery") {//数据服务-普通参数
                $("#sysIframe").attr("src", "DataContent.html?serviceId=" + treeNode.isMark);
            } else if (urlTxt == "singlereportshow") {//报表服务
                $("#sysIframe").attr("src", "ReportContent.html?serviceId=" + treeNode.isMark);
            } else if (urlTxt == "multipletableserver") {//数据服务-语法参数
                $("#sysIframe").attr("src", "DataGrammarContent.html?serviceId=" + treeNode.isMark);
            } else if (urlTxt == "getcensustableing") {//统计图表服务
                $("#sysIframe").attr("src", "StatisticsContent.html?serviceId=" + treeNode.isMark);
            } else if (urlTxt == "querymastertablelist") {//主从表服务
                $("#sysIframe").attr("src", "MasterDetailContent.html?serviceId=" + treeNode.isMark);
            } else if (urlTxt == "selecttreeconfig") {//资源树服务
                $("#sysIframe").attr("src", "ResourcesTree.html?serviceId=" + treeNode.isMark);
            }
        } else {
            $("#sysIframe").attr("src", "");
        }
    }
    //获取左侧列表数据
    function GetLeftTreeData() {
        var treeData;
        $.ajax({
            type: 'POST',
            url: serviceUrl + '/system/group/getGroupForTree',
            async: false,
            success: function (res) {
                treeData = res;
            }
        });
        return treeData;
    }
    //iframe高度自适应
    function setIframeHeight() {
        iframe = document.getElementById('sysIframe');
        if (iframe) {
            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
            if (iframeWin.document.body) {
                var strheight = document.documentElement.clientHeight - 45;
                iframe.height = strheight;
                $("#tree").css("height", strheight + "px");
            }
        }
    };
})